﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ZWZ.Web.Codes
{
    public class UserPower
    {
        protected const string AdminPowerKey = "Admin";
        protected string powerString;
        protected Dictionary<string, string[]> powers;

        public string PowerString { get { return powerString; } }
        public Dictionary<string, string[]> Powers { get { return powers; } }

        public UserPower(string PowerString)
        {
            this.powerString = PowerString;
            this.powers = SerializeHelper.DeserializeObjectByString(powerString) as Dictionary<string, string[]>;
        }

        public UserPower(Dictionary<string, string[]> Powers)
        {
            this.powers = Powers;
            this.powerString = SerializeHelper.SerializeObjectToString(powers);
        }

        public string[] GetPower(string key)
        {
            if (powers.Keys.Contains(key))
            {
                return powers[key];
            }
            else
            {
                return null;
            }
        }

        public bool CheckPower(string Key, string powerkey)
        {
            var ps = GetPower(Key);
            return (ps != null && ps.Contains(powerkey));
        }
    }
}